// pages/info/index.js
const { getMiaoShaInfo , getaddXiang } =require ("../../api/index");

Page({
  settlement(){
    wx.navigateTo({
      url: '../Settlement/index',
    })
  },
  /**
   * 页面的初始数据
   */
  data: {
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 500,
    //tab
    winWidth: 0,
    winHeight: 0,
    currentTab: 0,
    shopdetails:[],
    detail:{},
    tianjia:{},
  },
  changeIndicatorDots() {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay() {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  //接收数据
  onLoad: function (options) {
    let id = options.id
    getMiaoShaInfo({id:id*1}).then((res)=>{
      this.setData({
        detail:res.data.data
      })
    });
    
    var that = this;
    /**
     * 获取当前设备的宽高
     */
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }
    });
  },
// 添加购物车
  tianjia:function(options){
    let addList=options.currentTarget.dataset.item
    console.log(addList);
    getaddXiang(addList).then(res=>{
      console.log(res);
    })
    wx.showToast({
      title:'添加成功'
    })
  },
  //  tab切换逻辑
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  bindChange: function (e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  }
})
